package course.controller;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
<<<<<<< HEAD
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;
import java.sql.Connection;
import java.sql.SQLException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JTextField;

import course.po.Student;
import course.dao.impl.UserDaoImpl;
import course.db.DbConnection;
import course.po.Course;
import course.po.Dean;
import course.po.Teacher;
import course.po.User;
import course.service.impl.CourseServiceImpl;

import course.view.CourseDialog;
import course.view.CourseFrame;
import course.view.CourseJPanel;
import course.view.DJPanel;
import course.view.DeanDialog;
import course.view.DeanFrame;
import course.view.DeanJPanel;
import course.view.FunctionFrame;
import course.view.LoginFrame;
import course.view.PieChartFrame;
import course.view.StudentDialog;
import course.view.StudentFrame;
import course.view.StudentJPanel;
import course.view.TeacherDialog;
import course.view.TeacherFrame;
import course.view.TeacherJPanel;

public class CourseControllerListener implements ActionListener {

	private static LoginFrame loginFrame;
	public static String nameInput = "";
	public static String passWordInput;
	private StudentFrame studentFrame;
	private static CourseControllerListener controllerListener;
	private DeanFrame deanFrame;
	private TeacherFrame teacherFrame;
	private CourseDialog courseDialog;
	private CourseFrame courseFrame;
	private static CourseServiceImpl courseService;
	private DeanDialog deanDialog;
	private TeacherDialog teacherDialog;
	private StudentDialog studentDialog;
	private DeanJPanel deanJPanel;
	private StudentJPanel studentJPanel;
	private TeacherJPanel teacherJPanel;
	private CourseJPanel courseJPanel;
	private DJPanel djPanel;
	private FunctionFrame functionFrame;
	public static JScrollPane tablePanel;
	public static ArrayList<Integer> list;

	public CourseControllerListener() {
		courseService = new CourseServiceImpl();
	}

	/**
	 * 事件处理 实现用户登录、课程的增删改查
	 *
	 */
	@Override
	public void actionPerformed(ActionEvent e) {
		// 登录事件处理
		if ("addLoginDialog".equals(e.getActionCommand())) {
			nameInput = loginFrame.getNameTextField().getText().trim();

			passWordInput = loginFrame.getPassWordTextField().getText().trim();
			// 判空处理
			if (UserDaoImpl.isEmpty(nameInput)) {
				JOptionPane.showMessageDialog(null, "用户名不能为空");

			}
			if (UserDaoImpl.isEmpty(passWordInput)) {
				JOptionPane.showMessageDialog(null, "密码不能为空");
			}
			User user = new User(nameInput, passWordInput);
			DbConnection con = null;
			try {
				Connection conn = DbConnection.getConnection();
				User currentUser = courseService.login(con, user);
				if (currentUser != null) {
					if (LoginFrame.teaRadioButton.isSelected()) {
						teacherFrame = new TeacherFrame();
						JOptionPane.showMessageDialog(null, "登录老师界面成功");
					} else if (LoginFrame.stuRadioButton.isSelected()) {
						studentFrame = new StudentFrame();
						JOptionPane.showMessageDialog(null, "登录学生界面成功");
					} else if (LoginFrame.deaRadioButton.isSelected()) {
						deanFrame = new DeanFrame();
						JOptionPane.showMessageDialog(null, "登录教务员界面成功");
					} else {
						JOptionPane.showMessageDialog(null, "请选择用户类型");
					}
				} else {
					JOptionPane.showMessageDialog(null, "用户名或者密码错误");
				}
			}

			catch (Exception ex) {
				ex.printStackTrace();
			}
		}
		// 重置事件处理
		if ("addCancelDialog".equals(e.getActionCommand())) {
			loginFrame.getNameTextField().setText("");
			loginFrame.getPassWordTextField().setText("");
			loginFrame.getNameTextField().setForeground(Color.BLACK);
			loginFrame.getNameTextField().setForeground(Color.BLACK);
		}
		//教务员系统退出
		else if("gobackD".equals(e.getActionCommand())) {
			loginFrame.dispose();
			new LoginFrame();
			deanFrame.dispose();
		}
		
		// 学生个人信息
		else if ("studentData".equals(e.getActionCommand())) {
			studentFrame.drawStudent();
		}
		//学生系统退出
		else if("gobackS".equals(e.getActionCommand())) {
			loginFrame.dispose();
			new LoginFrame();
			studentFrame.dispose();
		}
		// 学生选课
		else if ("selectCourse".equals(e.getActionCommand())) {
			
			studentFrame.selectCourse();
		} else if ("findCourse".equals(e.getActionCommand())) {
		
			studentFrame.sCourse(StudentFrame.t1.getText());
			
		} else if ("confirmCourse".equals(e.getActionCommand())) {
			
			
			
			StudentFrame.readOut();
			if(StudentFrame.list.contains(StudentFrame.t2.getText())==false)  {
			//将选课记录读入course.txt
			try {
				Writer w = new FileWriter(StudentFrame.file,true);
				w.write("0"+"\n");
				w.write(StudentFrame.t2.getText()+"\n");
				w.flush();
				w.close();
				for(int i=0;i<StudentFrame.list.size();i++) {
				System.out.println(StudentFrame.list.get(i));
				}
				controllerListener = new CourseControllerListener();
				controllerListener.getCourseService().saveStuCou(controllerListener.getCourseService().getStudent(nameInput));
				new CourseControllerListener().getCourseService().hadSelectNum();
				JOptionPane.showMessageDialog(studentFrame,
						"选择" + Integer.valueOf(StudentFrame.t2.getText()) + "号课程成功！");
			} catch (IOException e2) {
				e2.printStackTrace();
			}
			
			} else {
//				for(int i=0;i< StudentFrame.num.length;i++) {
//					System.out.println( StudentFrame.num[i]);
//			StudentFrame.state=StudentFrame.list.contains(StudentFrame.t2.getText());
//                if(StudentFrame.state) {
                	JOptionPane.showMessageDialog(studentFrame,
						"不能重复选择该课程，你选择" + Integer.valueOf(StudentFrame.t2.getText()) + "号课程失败！");
//                }else if (courseService.getCourse(Integer.valueOf(StudentFrame.t2.getText())) != null&&StudentFrame.state==false) {
//                	try {
//                		studentFrame.addMyCourse();
//					} catch (SQLException e1) {
//						e1.printStackTrace();
//					}
                	
				//StudentFrame.refreshNum(courseService.getNotSelectedCourse(nameInput));
                }
			// 查询
		} else if ("researchGrade".equals(e.getActionCommand())) {
			System.out.println("yyy");
			teacherFrame.getStudentGrade(courseService.findTeaStu(nameInput));
		}
		// 学生已选课程表
		else if ("myCourse".equals(e.getActionCommand())) {
			
			studentFrame.myCourse(new CourseControllerListener().getCourseService().getSelectedCourse(nameInput));
		}
		//学生退课
		else if("deleteCourse".equals(e.getActionCommand())) {
			
		
				new CourseControllerListener().getCourseService().deleteNum(CourseJPanel.cI,nameInput);
				JOptionPane.showMessageDialog(studentFrame, "退课程编号为"+CourseJPanel.cI+"成功");
				studentFrame.myCourse(new CourseControllerListener().getCourseService().getSelectedCourse(nameInput));
			
		
		}
		//学生查看学分
	
		else if ("findLCourse".equals(e.getActionCommand())) {
			int credit = courseService.getCredit(StudentFrame.t1.getText());
			JOptionPane.showMessageDialog(studentFrame, credit+"学分");
		}
		//学生查看总学分
		
			else if ("FindACourse".equals(e.getActionCommand())) {
				int credit = courseService.getAllCredit();
				JOptionPane.showMessageDialog(studentFrame, credit+"学分");
			}
		//学生按课程名查看成绩
			else if ("searchGrade".equals(e.getActionCommand())) {
				studentFrame.myCourseGrade(new CourseControllerListener().getCourseService().getSelectedCourse(nameInput));

			}
			else if ("searchLGrade".equals(e.getActionCommand())) {
				int grade = courseService.getMyCourseNoGrade(StudentFrame.t1.getText());
				JOptionPane.showMessageDialog(studentFrame,StudentFrame.t1.getText()+"的成绩为"+grade);
			}
			else if("serachAGarde".equals(e.getActionCommand())) {
				int grade = courseService.getAverage();
				JOptionPane.showMessageDialog(studentFrame,"你所选择的所有课程的平均成绩为"+grade+"分");
			}
		// 教师信息
		else if ("teacherData".equals(e.getActionCommand())) {
			teacherFrame.drawTeacher();

		}
		//教师系统退出
		else if("gobackT".equals(e.getActionCommand())) {
			loginFrame.dispose();
			new LoginFrame();
			teacherFrame.dispose();
		}
		// 课程信息
		else if ("course".equals(e.getActionCommand())) {
			new CourseFrame();
		}
     
		// 教师查看所教课程
		else if ("courseList".equals(e.getActionCommand())) {
			teacherFrame.getTeaCou(nameInput);
		}
		else if ("timeCourse".equals(e.getActionCommand())) {
			teacherFrame.getTimeCou(TeacherFrame.t1.getText(),nameInput);
		}
		// 教师查看课程选修名单
		else if ("studentList".equals(e.getActionCommand())) {
			teacherFrame.getClaCou(nameInput);
		}
		//根据专业查找所教学生
		else if("classNo".equals(e.getActionCommand())) {
			teacherFrame.getCourseMaj(TeacherFrame.t1.getText(),nameInput);
		}
		// 教师录入、修改学生成绩
		else if ("suGrade".equals(e.getActionCommand())) {
			teacherFrame.getTeaStu(nameInput);
		} else if ("recGrade".equals(e.getActionCommand())) {
			courseService.updateStuGrade(nameInput, Integer.valueOf(TeacherFrame.t1.getText()),StudentJPanel.stuNo);
			TeacherFrame.refreshGrade(courseService.findTeaStu(nameInput));
			JOptionPane.showMessageDialog(teacherFrame, "成功录入成绩");

		} else if ("confirmGrade".equals(e.getActionCommand())) {
			courseService.updateStuGrade(nameInput, Integer.valueOf(TeacherFrame.t2.getText()),StudentJPanel.stuNo);
			TeacherFrame.refreshGrade(courseService.findTeaStu(nameInput));
			JOptionPane.showMessageDialog(teacherFrame, "成功修改成绩");
		}

		// 教师查看学生成绩
		else if ("researchGrade".equals(e.getActionCommand())) {
			teacherFrame.getTeaStu(nameInput);
		}
		// 打开查询对话框
		else if ("researchStuGrade".equals(e.getActionCommand())) {
			List<Student> studentList = new ArrayList<Student>();
			for (Student student : courseService.findAllStudent()) {
				studentList.add(student);
			}
			if (TeacherFrame.getT1().getText().trim() != null && !"".equals(TeacherFrame.getT1().getText().trim())) {
				if (TeacherFrame.comboBox1.getSelectedIndex() == 0) {
					if (TeacherFrame.getT1().getText().trim().matches("^[1-9][0-9]*([.][0-9]{1,2})?$")) {
						int classId = Integer.valueOf(TeacherFrame.getT1().getText().trim());
						List<Student> list = courseService.getClassNoGrade(classId,nameInput);
						teacherFrame.getStudentGrade(list);
					} else {
						JOptionPane.showMessageDialog(studentJPanel, "请输入数字", "输入错误", JOptionPane.ERROR_MESSAGE);
					}
				} else if (TeacherFrame.comboBox1.getSelectedIndex() == 1) {

					if (TeacherFrame.getT1().getText().trim().matches("^-?[0-9]+")) {
						String stuNo = TeacherFrame.getT1().getText().trim();
						List<Student> list = courseService.getStuNoGrade(stuNo,nameInput);
						teacherFrame.getStudentGrade(list);
					} else {
						JOptionPane.showMessageDialog(studentJPanel, "请输入数字字符串", "输入错误", JOptionPane.ERROR_MESSAGE);
					}
				} else if (TeacherFrame.getT1().getText().trim()!=null) {
					String couName = TeacherFrame.getT1().getText().trim();
					List<Student> list = courseService.getCourseNoGrade(couName,nameInput);
					teacherFrame.getStudentGrade(list);
				} else {
					JOptionPane.showMessageDialog(teacherFrame, "请输入字符", "输入错误", JOptionPane.ERROR_MESSAGE);
				}
			} else {
				JOptionPane.showMessageDialog(teacherFrame, "不能为空", "输入错误", JOptionPane.ERROR_MESSAGE);
			}
       //教师统计分析学生成绩情况
		}else if ("confirmMax".equals(e.getActionCommand())) {
				List<Student> studentList = new ArrayList<Student>();
				for (Student student : courseService.findAllStudent()) {
					studentList.add(student);
				}
				if (TeacherFrame.getT2().getText().trim() != null && !"".equals(TeacherFrame.getT2().getText().trim())) {
					if (TeacherFrame.comboBox2.getSelectedIndex() == 0) {
	
							int grade = courseService.getM();
							JOptionPane.showMessageDialog(teacherFrame,TeacherFrame.getT2().getText()+"这门课程的最高成绩为"+grade);
					} else if (TeacherFrame.comboBox2.getSelectedIndex() == 1) {
						int grade = courseService.getL();
						JOptionPane.showMessageDialog(teacherFrame,TeacherFrame.getT2().getText()+"这门课程的最低成绩为"+grade);
						
					} else if (TeacherFrame.comboBox2.getSelectedIndex() == 2) {
						int grade = courseService.getA();
						JOptionPane.showMessageDialog(teacherFrame,TeacherFrame.getT2().getText()+"这门课程的平均成绩为"+grade);
					} 
					else {
					     new PieChartFrame();
					}
				} else {
					JOptionPane.showMessageDialog(teacherFrame, "不能为空", "输入错误", JOptionPane.ERROR_MESSAGE);
				}
			// 打开新增课程对话框
		} else if ("addCourseDialog".equals(e.getActionCommand())) {
			courseDialog = new CourseDialog(courseJPanel, "添加课程", null);
		}
		// 新增课程提交
		else if ("addPost".equals(e.getActionCommand())) {
			Course newCourse = null;
			newCourse = this.getCourseInstance();
			if (newCourse != null) {
				courseService.addCourse(newCourse);
				JOptionPane.showMessageDialog(courseJPanel, "添加" + newCourse.getCouId() + "号课程成功！");
				courseDialog.dispose();
				CourseJPanel.refresh(courseService.findAllCourse());
			} else {
				JOptionPane.showMessageDialog(courseJPanel, "添加课程失败！");
			}
		}
		// 打开课程查询对话框
		else if ("searchCourseDialog".equals(e.getActionCommand())) {
			List<Course> courseList = new ArrayList<Course>();
			for (Course course : courseService.findAllCourse()) {
				courseList.add(course);
			}

			if (courseJPanel.getSearchTextField().getText().trim() != null
					&& !"".equals(courseJPanel.getSearchTextField().getText().trim())) {
				if (CourseJPanel.comboBox.getSelectedIndex() == 0) {
					if (courseJPanel.getSearchTextField().getText().trim().matches("^[1-9][0-9]*([.][0-9]{1,2})?$")) {
						int couId = Integer.valueOf(courseJPanel.getSearchTextField().getText().trim());
						Course course = new Course();
						course.setCouId(couId);

						List<Course> result = courseService.searchByCourseId(courseList, course);
						courseJPanel.showSearchResult(result);
					} else {
						JOptionPane.showMessageDialog(courseJPanel, "请输入数字", "输入错误", JOptionPane.ERROR_MESSAGE);
					}
				} else if (courseJPanel.getSearchTextField().getText().trim().matches("^[\\u4E00-\\u9FA5]{2,4}$")) {
					String courseName = courseJPanel.getSearchTextField().getText().trim();
					Course course = courseService.getCourseOne(courseName);
					List<Course> result = courseService.searchByCourseId(courseList, course);
					courseJPanel.showSearchResult(result);

				} else {
					JOptionPane.showMessageDialog(courseJPanel, "请输入汉字", "输入错误", JOptionPane.ERROR_MESSAGE);

				}
			}
			// 打开课程修改对话框
		} else if ("updateCourseDialog".equals(e.getActionCommand())) {
			int isbn = courseJPanel.getIsbn();
			if (isbn < 0) {
				JOptionPane.showMessageDialog(courseJPanel, "请选择一行数据！");
			} else {
				Course course = courseService.findAllCourse().get(courseJPanel.getIsbn());
				courseDialog = new CourseDialog(courseJPanel, "修改课程", course);
			}
		}
		// 修改课程提交
		else if ("updatePost".equals(e.getActionCommand())) {
			Course updatedCourse = this.getCourseInstance();
			if (updatedCourse != null) {
				courseService.updateCourse(updatedCourse);
				JOptionPane.showMessageDialog(courseJPanel, updatedCourse.getCouId() + "号课程修改成功！");
				courseDialog.dispose();
				CourseJPanel.refresh(courseService.findAllCourse());
			} else {
				JOptionPane.showMessageDialog(courseJPanel, "更新课程失败！");
			}
		}
		// 删除课程操作
		else if ("deleteCourseDialog".equals(e.getActionCommand())) {
			int isbn = courseJPanel.getIsbn();
			if (isbn < 0) {
				JOptionPane.showMessageDialog(courseJPanel, "请选择一行数据！");
			} else {
				Course course = courseService.findAllCourse().get(courseJPanel.getIsbn());
				courseService.deleteCourse(course.getCouId());
				JOptionPane.showMessageDialog(courseJPanel, "删除" + course.getCouId() + "号课程成功！");
				CourseJPanel.refresh(courseService.findAllCourse());
			}

		}
		// 刷新课程列表
		else if ("refreshCourseFrame".equals(e.getActionCommand())) {
			CourseJPanel.refresh(courseService.findAllCourse());

		}

		// 打开新增教务员对话框
		else if ("addDeanDialog".equals(e.getActionCommand())) {

			deanDialog = new DeanDialog(deanJPanel, "添加教务员", null);
		}
		// 新增教务员提交
		else if ("addDeanPost".equals(e.getActionCommand())) {
			Dean newDean = null;
			newDean = this.getDeanInstance();
			if (newDean != null) {
				courseService.addDean(newDean);
				JOptionPane.showMessageDialog(deanJPanel, "添加" + newDean.getDeaId() + "号教务员成功！");
				deanDialog.dispose();
				DeanJPanel.refreshDean(courseService.findAllDean());
			} else {
				JOptionPane.showMessageDialog(deanJPanel, "添加教务员失败！");
			}
		}

		// 打开教务员查询对话框
		else if ("searchDeanDialog".equals(e.getActionCommand())) {
			List<Dean> deanList = new ArrayList<Dean>();
			for (Dean dean : courseService.findAllDean()) {
				deanList.add(dean);
			}
			if (deanJPanel.getSearchTextField().getText().trim() != null
					&& !"".equals(deanJPanel.getSearchTextField().getText().trim())) {
				if (DeanJPanel.comboBox.getSelectedIndex() == 0) {
					if (deanJPanel.getSearchTextField().getText().trim().matches("^[1-9][0-9]*([.][0-9]{1,2})?$")) {
						int deaId = Integer.valueOf(deanJPanel.getSearchTextField().getText().trim());
						Dean dean = new Dean();
						dean.setDeaId(deaId);
						List<Dean> result = courseService.searchByDeanId(deanList, dean);
						deanJPanel.showDeanSearchResult(result);

					} else {
						JOptionPane.showMessageDialog(deanJPanel, "请输入数字", "输入错误", JOptionPane.ERROR_MESSAGE);
					}
				} else if (deanJPanel.getSearchTextField().getText().trim().matches("^[\\u4E00-\\u9FA5]{2,4}$")) {
					String deaName = deanJPanel.getSearchTextField().getText().trim();
					Dean dean = courseService.getDeanOne(deaName);
					List<Dean> result = courseService.searchByDeanId(deanList, dean);
					deanJPanel.showDeanSearchResult(result);

				} else {
					JOptionPane.showMessageDialog(deanJPanel, "请输入汉字", "输入错误", JOptionPane.ERROR_MESSAGE);
				}
			}
			// 打开教务员修改对话框
		} else if ("updateDeanDialog".equals(e.getActionCommand())) {
			int isbn = deanJPanel.getDeanIsbn();
			if (isbn < 0) {
				JOptionPane.showMessageDialog(deanJPanel, "请选择一行数据！");
			} else {
				Dean dean = courseService.findAllDean().get(deanJPanel.getDeanIsbn());
				deanDialog = new DeanDialog(deanJPanel, "修改教务员", dean);
			}
		}
		// 修改教务员提交
		else if ("updateDeanPost".equals(e.getActionCommand())) {
			Dean updatedDean = this.getDeanInstance();
			if (updatedDean != null) {
				courseService.updateDean(updatedDean);
				JOptionPane.showMessageDialog(deanJPanel, updatedDean.getDeaId() + "号教务员修改成功！");
				deanDialog.dispose();
				DeanJPanel.refreshDean(courseService.findAllDean());
			} else {
				JOptionPane.showMessageDialog(deanJPanel, "更新教务员失败！");
			}
		}
		// 删除教务员操作
		else if ("deleteDeanDialog".equals(e.getActionCommand())) {
			int isbn = deanJPanel.getDeanIsbn();
			if (isbn < 0) {
				JOptionPane.showMessageDialog(deanJPanel, "请选择一行数据！");
			} else {
				Dean dean = courseService.findAllDean().get(deanJPanel.getDeanIsbn());
				courseService.deleteDean(dean.getDeaId());
				JOptionPane.showMessageDialog(deanJPanel, "删除" + dean.getDeaId() + "号教务员成功！");
				DeanJPanel.refreshDean(courseService.findAllDean());
			}

		}
		// 刷新教务员列表
		else if ("refreshDeanFrame".equals(e.getActionCommand())) {
			DeanJPanel.refreshDean(courseService.findAllDean());
		}

		// 打开新增教师对话框
		else if ("addTeacherDialog".equals(e.getActionCommand())) {

			teacherDialog = new TeacherDialog(teacherJPanel, "添加教师", null);
		}
		// 新增教师提交
		else if ("addTeacherPost".equals(e.getActionCommand())) {
			Teacher newTeacher = null;
			newTeacher = this.getTeacherInstance();
			if (newTeacher != null) {
				courseService.addTeacher(newTeacher);
				JOptionPane.showMessageDialog(teacherJPanel, "添加" + newTeacher.getTeaId() + "号教师成功！");
				teacherDialog.dispose();
				TeacherJPanel.refreshTeacher(courseService.findAllTeacher());
			} else {
				JOptionPane.showMessageDialog(teacherJPanel, "添加教师失败！");
			}
		}
		// 打开教师查询对话框
		else if ("searchTeacherDialog".equals(e.getActionCommand())) {
			List<Teacher> teacherList = new ArrayList<Teacher>();
			for (Teacher teacher : courseService.findAllTeacher()) {
				teacherList.add(teacher);
			}
			if (teacherJPanel.getSearchTextField().getText().trim() != null
					&& !"".equals(teacherJPanel.getSearchTextField().getText().trim())) {
				if (TeacherJPanel.comboBox.getSelectedIndex() == 0) {
					if (teacherJPanel.getSearchTextField().getText().trim().matches("^[1-9][0-9]*([.][0-9]{1,2})?$")) {
						int teaId = Integer.valueOf(teacherJPanel.getSearchTextField().getText().trim());
						Teacher teacher = new Teacher();
						teacher.setTeaId(teaId);
						List<Teacher> result = courseService.searchByTeacherId(teacherList, teacher);
						teacherJPanel.showTeacherSearchResult(result);
					} else {
						JOptionPane.showMessageDialog(teacherJPanel, "请输入数字", "输入错误", JOptionPane.ERROR_MESSAGE);
					}
				} else if (teacherJPanel.getSearchTextField().getText().trim().matches("^[\\u4E00-\\u9FA5]{2,4}$")) {
					String teacherName = teacherJPanel.getSearchTextField().getText().trim();
					Teacher teacher = courseService.getTeacherOne(teacherName);
					List<Teacher> result = courseService.searchByTeacherId(teacherList, teacher);
					teacherJPanel.showTeacherSearchResult(result);

				} else {
					JOptionPane.showMessageDialog(teacherJPanel, "请输入汉字", "输入错误", JOptionPane.ERROR_MESSAGE);
				}

			}

			// 打开教师修改对话框
		} else if ("updateTeacherDialog".equals(e.getActionCommand())) {
			int isbn = teacherJPanel.getTeacherIsbn();
			if (isbn < 0) {
				JOptionPane.showMessageDialog(teacherJPanel, "请选择一行数据！");
			} else {
				Teacher teacher = courseService.findAllTeacher().get(teacherJPanel.getTeacherIsbn());
				teacherDialog = new TeacherDialog(teacherJPanel, "修改教师", teacher);
			}
		}
		// 修改教师提交
		else if ("updateTeacherPost".equals(e.getActionCommand())) {
			Teacher updatedTeacher = this.getTeacherInstance();
			if (updatedTeacher != null) {
				courseService.updateTeacher(updatedTeacher);
				JOptionPane.showMessageDialog(teacherJPanel, updatedTeacher.getTeaId() + "号教师修改成功！");
				teacherDialog.dispose();
				TeacherJPanel.refreshTeacher(courseService.findAllTeacher());
			} else {
				JOptionPane.showMessageDialog(teacherJPanel, "更新教师失败！");
			}
		}
		// 删除教师操作
		else if ("deleteTeacherDialog".equals(e.getActionCommand())) {
			int isbn = teacherJPanel.getTeacherIsbn();
			System.out.println(isbn);
			if (isbn < 0) {
				JOptionPane.showMessageDialog(teacherJPanel, "请选择一行数据！");
			} else {
				Teacher teacher = courseService.findAllTeacher().get(teacherJPanel.getTeacherIsbn());
				courseService.deleteTeacher(teacher.getTeaId());
				JOptionPane.showMessageDialog(teacherJPanel, "删除" + teacher.getTeaId() + "号教师成功！");
				TeacherJPanel.refreshTeacher(courseService.findAllTeacher());
			}

		}
		// 刷新教师列表
		else if ("refreshTeacherFrame".equals(e.getActionCommand())) {
			TeacherJPanel.refreshTeacher(courseService.findAllTeacher());
		}

		// 打开新增学生对话框
		else if ("addStudentDialog".equals(e.getActionCommand())) {
			studentDialog = new StudentDialog(studentJPanel, "添加学生", null);
		}
		// 新增学生提交
		else if ("addStudentPost".equals(e.getActionCommand())) {
			Student newStudent = null;
			newStudent = this.getStudentInstance();
			if (newStudent != null) {
				courseService.addStudent(newStudent);
				JOptionPane.showMessageDialog(studentJPanel, "添加" + newStudent.getStuId() + "号学生成功！");
				studentDialog.dispose();
				StudentJPanel.refreshStudent(courseService.findAllStudent());
			} else {
				JOptionPane.showMessageDialog(studentJPanel, "添加学生失败！");
			}
		}
		// 打开学生查询对话框
		else if ("searchStudentDialog".equals(e.getActionCommand())) {
			List<Student> studentList = new ArrayList<Student>();
			for (Student student : courseService.findAllStudent()) {
				studentList.add(student);
			}
			if (studentJPanel.getSearchTextField().getText().trim() != null
					&& !"".equals(studentJPanel.getSearchTextField().getText().trim())) {
				if (StudentJPanel.comboBox.getSelectedIndex() == 0) {
					if (studentJPanel.getSearchTextField().getText().trim().matches("^[1-9][0-9]*([.][0-9]{1,2})?$")) {
						int studentId = Integer.valueOf(studentJPanel.getSearchTextField().getText().trim());
						Student student = new Student();
						student.setStuId(studentId);
						List<Student> result = courseService.searchByStudentId(studentList, student);
						studentJPanel.showStudentSearchResult(result);
					} else {
						JOptionPane.showMessageDialog(studentJPanel, "请输入数字", "输入错误", JOptionPane.ERROR_MESSAGE);
					}
				} else if (studentJPanel.getSearchTextField().getText().trim().matches("^[\\u4E00-\\u9FA5]{2,4}$")) {
					String studentName = studentJPanel.getSearchTextField().getText().trim();
					Student student = courseService.getStudentOne(studentName);
					List<Student> result = courseService.searchByStudentId(studentList, student);
					studentJPanel.showStudentSearchResult(result);

				} else {
					JOptionPane.showMessageDialog(studentJPanel, "请输入汉字", "输入错误", JOptionPane.ERROR_MESSAGE);
				}

			}
			// 打开修改学生对话框
		} else if ("updateStudentDialog".equals(e.getActionCommand())) {
			int isbn = studentJPanel.getStudentIsbn();
			if (isbn < 0) {
				JOptionPane.showMessageDialog(studentJPanel, "请选择一行数据！");
			} else {
				Student student = courseService.findAllStudent().get(studentJPanel.getStudentIsbn());
				studentDialog = new StudentDialog(studentJPanel, "修改学生", student);
			}
		}
		// 修改学生提交
		else if ("updateStudentPost".equals(e.getActionCommand())) {
			Student updatedStudent = this.getStudentInstance();
			if (updatedStudent != null) {
				courseService.updateStudent(updatedStudent);
				JOptionPane.showMessageDialog(studentJPanel, updatedStudent.getStuId() + "号学生修改成功！");
				studentDialog.dispose();
				StudentJPanel.refreshStudent(courseService.findAllStudent());
			} else {
				JOptionPane.showMessageDialog(studentJPanel, "更新学生失败！");
			}
		}
		// 删除学生操作
		else if ("deleteStudentDialog".equals(e.getActionCommand())) {
			int isbn = studentJPanel.getStudentIsbn();
			if (isbn < 0) {
				JOptionPane.showMessageDialog(studentJPanel, "请选择一行数据！");
			} else {
				Student student = courseService.findAllStudent().get(studentJPanel.getStudentIsbn());
				courseService.deleteStudent(student.getStuId());
				JOptionPane.showMessageDialog(studentJPanel, "删除" + student.getStuId() + "号学生成功！");
				StudentJPanel.refreshStudent(courseService.findAllStudent());
			}
		}
		// 刷新学生列表窗口
		else if ("refreshStudentFrame".equals(e.getActionCommand())) {
			StudentJPanel.refreshStudent(courseService.findAllStudent());

		}
	}

//得到学生基本信息
	private Student getStudentInstance() {
		int stuId = 0;
		String stuNo = null;
		String stuName = null;
		String stuSex = null;
		Date stuAge = null;
		String stuMajor = null;
		int stuClassNo = 0;
		int couId = 0;
		String couName = null;
		int stuGrade = 0;
		java.sql.Date sqlDate = null;
		Course course = null;

		Student student = null;
		String stuIdInput = studentDialog.getStudentIdTextField().getText().trim();
		if (stuIdInput != null && !"".equals(stuIdInput)) {
			if (stuIdInput.matches("^[1-9][0-9]*([.][0-9]{1,2})?$")) {
				stuId = Integer.parseInt(stuIdInput);
			} else {
				JOptionPane.showMessageDialog(studentFrame, "编号必须是正整数类型", "输入错误", JOptionPane.ERROR_MESSAGE);
			}
		} else {
			JOptionPane.showMessageDialog(studentFrame, "编号不能为空", "输入错误", JOptionPane.ERROR_MESSAGE);
		}

		String stuNoInput = studentDialog.getStudentNoTextField().getText().trim();
		if (stuNoInput != null && !"".equals(stuNoInput)) {
			stuNo = stuNoInput;
		} else {
			JOptionPane.showMessageDialog(studentFrame, "学号不能为空", "输入错误", JOptionPane.ERROR_MESSAGE);
		}
		String stuNameInput = studentDialog.getStudentNameTextField().getText().trim();
		if (stuNameInput != null && !"".equals(stuNameInput)) {
			stuName = stuNameInput;
		} else {
			JOptionPane.showMessageDialog(studentFrame, "姓名不能为空", "输入错误", JOptionPane.ERROR_MESSAGE);
		}
		
		if (studentDialog.getRadioMan().isSelected()) {
			stuSex="男";
		} 
		else if(studentDialog.getRadioFemal().isSelected()){
			stuSex = "女";
		
		} else {
			JOptionPane.showMessageDialog(studentFrame, "性别不能为空", "输入错误", JOptionPane.ERROR_MESSAGE);
		}
		String dateInput = studentDialog.getStudentAgeTextField().getText().trim();
		if (dateInput != null && !"".equals(dateInput)) {
			SimpleDateFormat ft = new SimpleDateFormat("yyyy-MM-dd");
			try {
				stuAge = new SimpleDateFormat("yyyy-MM-dd").parse(dateInput);
				sqlDate = new java.sql.Date(stuAge.getTime());
			} catch (ParseException e) {
				JOptionPane.showMessageDialog(studentFrame, "年龄类型错误", "输入错误", JOptionPane.ERROR_MESSAGE);
			}
		} else {
			JOptionPane.showMessageDialog(studentFrame, "年龄不能为空", "输入错误", JOptionPane.ERROR_MESSAGE);
		}
		String stuMajorInput = studentDialog.getStudentMajorTextField().getText().trim();
		if (stuMajorInput != null && !"".equals(stuMajorInput)) {
			stuMajor = stuMajorInput;
		} else {
			JOptionPane.showMessageDialog(studentFrame, "专业不能为空", "输入错误", JOptionPane.ERROR_MESSAGE);
		}
		String stuClassNoInput = studentDialog.getStudentClassNoTextField().getText().trim();
		if (stuClassNoInput != null && !"".equals(stuIdInput)) {
			if (stuClassNoInput.matches("^[1-9][0-9]*([.][0-9]{1,2})?$")) {
				stuClassNo = Integer.parseInt(stuClassNoInput);
			} else {
				JOptionPane.showMessageDialog(studentFrame, "班级号必须是正整数类型", "输入错误", JOptionPane.ERROR_MESSAGE);
			}
		} else {
			JOptionPane.showMessageDialog(studentFrame, "班级号不能为空", "输入错误", JOptionPane.ERROR_MESSAGE);
		}
		String couIdInput = studentDialog.getCourseIdTextField().getText().trim();
		if (couIdInput != null && !"".equals(couIdInput)) {
			if (couIdInput.matches("^[1-9][0-9]*([.][0-9]{1,2})?$")) {
				couId = Integer.parseInt(couIdInput);
				course = courseService.getCourse(couId);
			} else {
				JOptionPane.showMessageDialog(studentFrame, "课程编号必须是正整数类型", "输入错误", JOptionPane.ERROR_MESSAGE);
			}
		} else {
			JOptionPane.showMessageDialog(studentFrame, "课程编号不能为空", "输入错误", JOptionPane.ERROR_MESSAGE);
		}
		String stuGradeInput = studentDialog.getStudentGradeTextField().getText().trim();
		if (stuGradeInput != null && !"".equals(stuGradeInput)) {
			if (stuGradeInput.matches("^[0-9]*$")) {
				stuGrade = Integer.parseInt(stuGradeInput);
			} else {
				JOptionPane.showMessageDialog(studentFrame, "成绩必须是数字类型", "输入错误", JOptionPane.ERROR_MESSAGE);
			}
		} else {
			JOptionPane.showMessageDialog(studentFrame, "成绩不能为空", "输入错误", JOptionPane.ERROR_MESSAGE);
		}

		if (stuId > 0 && stuNo != null && stuName != null && stuSex != null && sqlDate != null && stuMajor != null
				&& stuClassNo > 0 && couId > 0 && stuGrade >= 0 && course != null) {
			student = new Student(stuId, stuNo, stuName, stuSex, sqlDate, stuMajor, stuClassNo, stuGrade, course);
		}
		return student;
	}

	// 得到教师基本信息
	private Teacher getTeacherInstance() {
		int teaId = 0;
		String teaNo = null;
		String teaName = null;
		String teaSex = null;
		Date teaAge = null;
		int couId = 0;
		java.sql.Date sqlDate = null;
		Course course = null;
		Teacher teacher = null;
		String teaIdInput = teacherDialog.getTeacherIdTextField().getText().trim();
		if (teaIdInput != null && !"".equals(teaIdInput)) {
			if (teaIdInput.matches("^[1-9][0-9]*([.][0-9]{1,2})?$")) {
				teaId = Integer.parseInt(teaIdInput);
			} else {
				JOptionPane.showMessageDialog(teacherFrame, "编号必须是正整数类型", "输入错误", JOptionPane.ERROR_MESSAGE);
			}
		} else {
			JOptionPane.showMessageDialog(teacherFrame, "编号不能为空", "输入错误", JOptionPane.ERROR_MESSAGE);
		}

		String teaNoInput = teacherDialog.getTeacherNoTextField().getText().trim();
		if (teaNoInput != null && !"".equals(teaNoInput)) {
			teaNo = teaNoInput;
		} else {
			JOptionPane.showMessageDialog(teacherFrame, "教职工号不能为空", "输入错误", JOptionPane.ERROR_MESSAGE);
		}
		String teaNameInput = teacherDialog.getTeacherNameTextField().getText().trim();
		if (teaNameInput != null && !"".equals(teaNameInput)) {
			teaName = teaNameInput;
		} else {
			JOptionPane.showMessageDialog(teacherFrame, "姓名不能为空", "输入错误", JOptionPane.ERROR_MESSAGE);
		}
		if (teacherDialog.getRadioMan().isSelected()) {
			teaSex="男";
		} 
		else if(teacherDialog.getRadioFemal().isSelected()){
			teaSex = "女";
		
		} else {
			JOptionPane.showMessageDialog(teacherFrame, "性别不能为空", "输入错误", JOptionPane.ERROR_MESSAGE);
		}
		String dateInput = teacherDialog.getTeacherAgeTextField().getText().trim();
		if (dateInput != null && !"".equals(dateInput)) {
			SimpleDateFormat ft = new SimpleDateFormat("yyyy-MM-dd");
			try {
				teaAge = new SimpleDateFormat("yyyy-MM-dd").parse(dateInput);
				sqlDate = new java.sql.Date(teaAge.getTime());
			} catch (ParseException e) {
				JOptionPane.showMessageDialog(teacherFrame, "年龄类型错误", "输入错误", JOptionPane.ERROR_MESSAGE);
			}
		} else {
			JOptionPane.showMessageDialog(teacherFrame, "年龄不能为空", "输入错误", JOptionPane.ERROR_MESSAGE);
		}
		String couIdInput = teacherDialog.getCourseIdTextField().getText().trim();
		if (couIdInput != null && !"".equals(couIdInput)) {
			if (couIdInput.matches("^[1-9][0-9]*([.][0-9]{1,2})?$")) {
				couId = Integer.parseInt(couIdInput);
				course = courseService.getCourse(couId);
			} else {
				JOptionPane.showMessageDialog(teacherFrame, "课程编号必须是正整数类型", "输入错误", JOptionPane.ERROR_MESSAGE);
			}
		} else {
			JOptionPane.showMessageDialog(teacherFrame, "课程编号不能为空", "输入错误", JOptionPane.ERROR_MESSAGE);
		}
		if (teaId > 0 && teaNo != null && teaName != null && teaSex != null && sqlDate != null && course != null) {
			teacher = new Teacher(teaId, teaNo, teaName, teaSex, sqlDate, course);
		}
		return teacher;
	}

	// 得到课程基本信息
	private Course getCourseInstance() {
		int couId = 0;
		String couType = null;
		String couNo = null;
		String couName = null;
		String couDetail = null;
		int couCredit = 0;
		int teaId = 0;
		Teacher teacher = null;
		String teaName = null;
		int maxNumber = 0;
		int selectNumber = 0;
		Course course = null;
		String couIdInput = courseDialog.getCourseIdTextField().getText().trim();
		if (couIdInput != null && !"".equals(couIdInput)) {
			if (couIdInput.matches("^[1-9][0-9]*([.][0-9]{1,2})?$")) {
				couId = Integer.parseInt(couIdInput);
			} else {
				JOptionPane.showMessageDialog(courseFrame, "编号必须是正整数类型", "输入错误", JOptionPane.ERROR_MESSAGE);
			}
		} else {
			JOptionPane.showMessageDialog(courseFrame, "编号不能为空", "输入错误", JOptionPane.ERROR_MESSAGE);
		}
		String couTypeInput = courseDialog.getCourseTypeTextField().getText().trim();
		if (couTypeInput != null && !"".equals(couTypeInput)) {
			couType = couTypeInput;
		} else {
			JOptionPane.showMessageDialog(courseFrame, "课程类型不能为空", "输入错误", JOptionPane.ERROR_MESSAGE);
		}

		String couNoInput = courseDialog.getCourseNoTextField().getText().trim();
		if (couNoInput != null && !"".equals(couNoInput)) {
			couNo = couNoInput;
		} else {
			JOptionPane.showMessageDialog(courseFrame, "课程号不能为空", "输入错误", JOptionPane.ERROR_MESSAGE);
		}
		String couNameInput = courseDialog.getCourseNameTextField().getText().trim();
		if (couNameInput != null && !"".equals(couNameInput)) {
			couName = couNameInput;
		} else {
			JOptionPane.showMessageDialog(courseFrame, "课程名不能为空", "输入错误", JOptionPane.ERROR_MESSAGE);
		}
		String couDetailInput = courseDialog.getCourseDetailTextField().getText().trim();
		if (couDetailInput != null && !"".equals(couDetailInput)) {
			couDetail = couDetailInput;
		} else {
			JOptionPane.showMessageDialog(courseFrame, "时间/地点不能为空", "输入错误", JOptionPane.ERROR_MESSAGE);
		}
		String couCreditInput = courseDialog.getCourseCreditTextField().getText().trim();
		if (couCreditInput != null && !"".equals(couCreditInput)) {
			if (couIdInput.matches("^[1-9][0-9]*([.][0-9]{1,2})?$")) {
				couCredit = Integer.parseInt(couCreditInput);
			} else {
				JOptionPane.showMessageDialog(courseFrame, "学分必须是正整数类型", "输入错误", JOptionPane.ERROR_MESSAGE);
			}
		} else {
			JOptionPane.showMessageDialog(courseFrame, "学分不能为空", "输入错误", JOptionPane.ERROR_MESSAGE);
		}
		String teaIdInput = courseDialog.getTeacherIdTextField().getText().trim();
		if (teaIdInput != null && !"".equals(teaIdInput)) {
			if (teaIdInput.matches("^[1-9][0-9]*([.][0-9]{1,2})?$")) {
				teaId = Integer.parseInt(teaIdInput);
				teacher = courseService.getTeacher(teaId);
			} else {
				JOptionPane.showMessageDialog(courseFrame, "教师编号必须是正整数类型", "输入错误", JOptionPane.ERROR_MESSAGE);
			}
		} else {
			JOptionPane.showMessageDialog(courseFrame, "教师编号不能为空", "输入错误", JOptionPane.ERROR_MESSAGE);
		}
		String maxNumberInput = courseDialog.getMaxNumberTextField().getText().trim();
		if (maxNumberInput != null && !"".equals(maxNumberInput)) {
			if (maxNumberInput.matches("^[1-9][0-9]*([.][0-9]{1,2})?$")) {
				maxNumber = Integer.parseInt(maxNumberInput);
			} else {
				JOptionPane.showMessageDialog(courseFrame, "课程容量必须是正整数类型", "输入错误", JOptionPane.ERROR_MESSAGE);
			}
		} else {
			JOptionPane.showMessageDialog(courseFrame, "课程容量不能为空", "输入错误", JOptionPane.ERROR_MESSAGE);
		}
		String selectNumberInput = courseDialog.getSelectNumberTextField().getText().trim();
		if (selectNumberInput != null && !"".equals(selectNumberInput)) {
			if (selectNumberInput.matches("^[0-9]*$")) {
				selectNumber = Integer.parseInt(selectNumberInput);
			} else {
				JOptionPane.showMessageDialog(courseFrame, "已选人数必须是数字类型", "输入错误", JOptionPane.ERROR_MESSAGE);
			}
		} else {
			JOptionPane.showMessageDialog(courseFrame, "已选人数不能为空", "输入错误", JOptionPane.ERROR_MESSAGE);
		}
		if (couId > 0 && couType != null && couNo != null && couName != null && couDetail != null && couCredit > 0
				&& teacher != null && maxNumber > 0 && selectNumber >= 0) {
			course = new Course(couId, couType, couNo, couName, couDetail, couCredit, maxNumber, selectNumber, teacher);
		}
		return course;
	}

	// 得到教务员基本信息
	private Dean getDeanInstance() {
		int deaId = 0;
		String deaNo = null;
		String deaName = null;
		String deaSex = null;
		Date deaAge = null;
		java.sql.Date sqlDate = null;
		Dean dean = null;
		String deaIdInput = deanDialog.getDeanIdTextField().getText().trim();
		if (deaIdInput != null && !"".equals(deaIdInput)) {
			if (deaIdInput.matches("^[1-9][0-9]*([.][0-9]{1,2})?$")) {
				deaId = Integer.parseInt(deaIdInput);
			} else {
				JOptionPane.showMessageDialog(deanFrame, "编号必须是数字类型", "输入错误", JOptionPane.ERROR_MESSAGE);
			}
		} else {
			JOptionPane.showMessageDialog(deanFrame, "编号不能为空", "输入错误", JOptionPane.ERROR_MESSAGE);
		}

		String deaNoInput = deanDialog.getDeanNoTextField().getText().trim();
		if (deaNoInput != null && !"".equals(deaNoInput)) {
			deaNo = deaNoInput;
		} else {
			JOptionPane.showMessageDialog(deanFrame, "教职工号不能为空", "输入错误", JOptionPane.ERROR_MESSAGE);
		}
		String deaNameInput = deanDialog.getDeanNameTextField().getText().trim();
		if (deaNameInput != null && !"".equals(deaNameInput)) {
			deaName = deaNameInput;
		} else {
			JOptionPane.showMessageDialog(deanFrame, "姓名不能为空", "输入错误", JOptionPane.ERROR_MESSAGE);
		}
		if (deanDialog.getRadioMan().isSelected()) {
			deaSex="男";
		} 
		else if(deanDialog.getRadioFemal().isSelected()){
			deaSex = "女";
		
		} else {
			JOptionPane.showMessageDialog(deanFrame, "性别不能为空", "输入错误", JOptionPane.ERROR_MESSAGE);
		}
		String dateInput = deanDialog.getDeanAgeTextField().getText().trim();
		System.out.print(deanDialog.getDeanAgeTextField().getText().trim());
		if (dateInput != null && !"".equals(dateInput)) {
			SimpleDateFormat ft = new SimpleDateFormat("yyyy-MM-dd");
			try {
				deaAge = new SimpleDateFormat("yyyy-MM-dd").parse(dateInput);
				sqlDate = new java.sql.Date(deaAge.getTime());
			} catch (ParseException e) {
				JOptionPane.showMessageDialog(deanFrame, "年龄类型错误", "输入错误", JOptionPane.ERROR_MESSAGE);
			}
		} else {
			JOptionPane.showMessageDialog(deanFrame, "年龄不能为空", "输入错误", JOptionPane.ERROR_MESSAGE);
		}

		if (deaId > 0 && deaNo != null && deaName != null && deaSex != null && sqlDate != null) {
			dean = new Dean(deaId, deaNo, deaName, deaSex, sqlDate);
		}
		return dean;
	}

	public void setStudentFrame(StudentFrame studentFrame) {
		this.studentFrame = studentFrame;

	}

	public void setLoginFrame(LoginFrame loginFrame) {
		this.loginFrame = loginFrame;

	}

	public void setDeanFrame(DeanFrame deanFrame) {
		this.deanFrame = deanFrame;

	}

	public void setTeacherFrame(TeacherFrame teacherFrame) {
		this.teacherFrame = teacherFrame;

	}

	public void setCourseAddDialog(CourseDialog courseDialog) {
		this.courseDialog = courseDialog;

	}

	public void setCourseFrame(CourseFrame courseFrame) {
		this.courseFrame = courseFrame;

	}

	public CourseServiceImpl getCourseService() {
		return courseService;
	}

	public void setDeanAddDialog(DeanDialog deanDialog) {
		this.deanDialog = deanDialog;

	}

	public void setTeacherAddDialog(TeacherDialog teacherDialog) {
		this.teacherDialog = teacherDialog;

	}

	public void setStudentAddDialog(StudentDialog studentDialog) {
		this.studentDialog = studentDialog;

	}

	public void setDeanPanel(DeanJPanel deanJPanel) {
		this.deanJPanel = deanJPanel;
	}

	public void setStudentPanel(StudentJPanel studentJPanel) {
		this.studentJPanel = studentJPanel;
	}

	public void setTeachertPanel(TeacherJPanel teacherJPanel) {
		this.teacherJPanel = teacherJPanel;

	}

	public void setCoursePanel(CourseJPanel courseJPanel) {
		this.courseJPanel = courseJPanel;

	}

	public static String getNameInput() {
		return nameInput;
	}

	public static void setNameInput(String nameInput) {
		CourseControllerListener.nameInput = nameInput;
	}

	public static String getPassWordInput() {
		return passWordInput;
	}

	public static void setPassWordInput(String passWordInput) {
		CourseControllerListener.passWordInput = passWordInput;
	}

	public void setDJPanel(DJPanel djPanel) {
		this.djPanel = djPanel;
		
	}

	public void setFunctionFrame(FunctionFrame functionFrame) {
		this.functionFrame= functionFrame;
		
	}
	
}
=======
import java.sql.Connection;
import java.sql.SQLException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;

import course.po.Student;
import course.dao.impl.UserDaoImpl;
import course.db.DbConnection;
import course.po.Course;
import course.po.Dean;
import course.po.Teacher;
import course.po.User;
import course.service.impl.CourseServiceImpl;

import course.view.CourseDialog;
import course.view.CourseFrame;
import course.view.CourseJPanel;
import course.view.DeanDialog;
import course.view.DeanFrame;
import course.view.DeanJPanel;
import course.view.LoginFrame;

import course.view.StudentDialog;
import course.view.StudentFrame;
import course.view.StudentJPanel;
import course.view.TeacherDialog;
import course.view.TeacherFrame;
import course.view.TeacherJPanel;

public class CourseControllerListener implements ActionListener {

	private LoginFrame loginFrame;
	public static String nameInput;
	public static String passWordInput;
	private StudentFrame studentFrame;
	private static CourseControllerListener controllerListener;
	private DeanFrame deanFrame;
	private TeacherFrame teacherFrame;
	private CourseDialog courseDialog;
	private CourseFrame courseFrame;
	private CourseServiceImpl courseService;
	private DeanDialog deanDialog;
	private TeacherDialog teacherDialog;
	private StudentDialog studentDialog;
	private DeanJPanel deanJPanel;
	private StudentJPanel studentJPanel;
	private TeacherJPanel teacherJPanel;
	private CourseJPanel courseJPanel;
	public static JScrollPane tablePanel;
	public static ArrayList<Integer> list;

	public CourseControllerListener() {
		courseService = new CourseServiceImpl();
	}

	/**
	 * 事件处理 实现用户登录、课程的增删改查
	 *
	 */
	@Override
	public void actionPerformed(ActionEvent e) {
		// 登录事件处理
		if ("addLoginDialog".equals(e.getActionCommand())) {
			nameInput = loginFrame.getNameTextField().getText().trim();
			passWordInput = loginFrame.getPassWordTextField().getText().trim();

			// 判空处理
			if (UserDaoImpl.isEmpty(nameInput)) {
				JOptionPane.showMessageDialog(null, "用户名不能为空");

			}
			if (UserDaoImpl.isEmpty(passWordInput)) {
				JOptionPane.showMessageDialog(null, "密码不能为空");
			}
			User user = new User(nameInput, passWordInput);
			DbConnection con = null;
			try {
				Connection conn = DbConnection.getConnection();
				User currentUser = courseService.login(con, user);
				if (currentUser != null) {
					if (LoginFrame.teaRadioButton.isSelected()) {
						teacherFrame = new TeacherFrame();
						JOptionPane.showMessageDialog(null, "登录老师界面成功");
					} else if (LoginFrame.stuRadioButton.isSelected()) {
						studentFrame = new StudentFrame();
						JOptionPane.showMessageDialog(null, "登录学生界面成功");
					} else if (LoginFrame.deaRadioButton.isSelected()) {
						deanFrame = new DeanFrame();
						JOptionPane.showMessageDialog(null, "登录教务员界面成功");
					} else {
						JOptionPane.showMessageDialog(null, "请选择用户类型");
					}
				} else {
					JOptionPane.showMessageDialog(null, "用户名或者密码错误");
				}
			}

			catch (Exception ex) {
				ex.printStackTrace();
			}
		}

		// 重置事件处理
		if ("addCancelDialog".equals(e.getActionCommand())) {
			loginFrame.getNameTextField().setText("");
			loginFrame.getPassWordTextField().setText("");
			loginFrame.getNameTextField().setForeground(Color.BLACK);
			loginFrame.getNameTextField().setForeground(Color.BLACK);
		}
		// 学生个人信息
		else if ("studentData".equals(e.getActionCommand())) {
			studentFrame.drawStudent();
		}
		// 学生选课
		else if ("selectCourse".equals(e.getActionCommand())) {
			studentFrame.selectCourse();
		} else if ("findCourse".equals(e.getActionCommand())) {
			StudentFrame.p1.removeAll();
			StudentFrame.p1.repaint();
			StudentFrame.p1.add(CourseJPanel.getCourseTablePanel(courseService.getCourse()), BorderLayout.CENTER);	
			StudentFrame.p1.revalidate();
		} else if ("confirmCourse".equals(e.getActionCommand())) {
//			try {
//				int selectedNum = StudentFrame.hadSelectNum();
//				if (selectedNum == 1) {
//					studentFrame.addMyCourse();
//					JOptionPane.showMessageDialog(studentFrame,
//							"选择" + Integer.valueOf(StudentFrame.t2.getText()) + "号课程成功！");
//				} else {
//					JOptionPane.showMessageDialog(studentFrame, "选课失败!");
//				}
//			} catch (Exception ee) {
//				ee.printStackTrace();
//				JOptionPane.showMessageDialog(studentFrame, "已选过该门课程!");
//			}
//			StudentFrame.p1.revalidate()
			try {
				studentFrame.addMyCourse();

			} catch (SQLException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
			if (courseService.getCourse(Integer.valueOf(StudentFrame.t2.getText())) != null) {
				JOptionPane.showMessageDialog(studentFrame,
						"选择" + Integer.valueOf(StudentFrame.t2.getText()) + "号课程成功！");
				StudentFrame.refreshNum(courseService.findAllCourse());
			} else {
      }
		//查询
		} else if ("researchGrade".equals(e.getActionCommand())) {
			System.out.println("yyy");
			teacherFrame.getStudentGrade();
		}
		// 学生已选课程表
		else if ("myCourse".equals(e.getActionCommand())) {
			System.out.println("aaa");
			studentFrame.myCourse();
			StudentFrame.p2.revalidate();
		} 
		//教师信息
		else if ("teacherData".equals(e.getActionCommand())) {
			System.out.println("bbb");
			teacherFrame.drawTeacher();
			
		} 
		//课程信息
		else if ("course".equals(e.getActionCommand())) {
			new CourseFrame();
		}

		// 教师查看所教课程
		else if ("courseList".equals(e.getActionCommand())) {
			teacherFrame.getTeaCou(nameInput);
		}
		// 教师查看课程选修名单
		else if ("studentList".equals(e.getActionCommand())) {
			teacherFrame.getTeaStu(nameInput);
		}
		// 教师录入、修改学生成绩
		else if ("suGrade".equals(e.getActionCommand())) {
			teacherFrame.getTeaStu(nameInput);
		} else if ("recGrade".equals(e.getActionCommand())) {
			courseService.updateStuGrade(nameInput, Integer.valueOf(TeacherFrame.t1.getText()));
			TeacherFrame.refreshGrade(courseService.findTeaStu(nameInput));
			JOptionPane.showMessageDialog(teacherFrame, "成功录入成绩");

		} else if ("confirmGrade".equals(e.getActionCommand())) {
			courseService.updateStuGrade(nameInput, Integer.valueOf(TeacherFrame.t2.getText()));
			TeacherFrame.refreshGrade(courseService.findTeaStu(nameInput));
			JOptionPane.showMessageDialog(teacherFrame, "成功修改成绩");
		}

		// 教师查看学生成绩
		else if ("researchGrade".equals(e.getActionCommand())) {
			teacherFrame.getTeaStu(nameInput);
		}
		// 打开查询对话框
		else if ("researchStuGrade".equals(e.getActionCommand())) {
			List<Student> studentList = new ArrayList<Student>();
			for (Student student : courseService.findAllStudent()) {
				studentList.add(student);
			}
			if (TeacherFrame.getT1().getText().trim() != null && !"".equals(TeacherFrame.getT1().getText().trim())) {
				if (TeacherFrame.comboBox1.getSelectedIndex() == 0) {
					if (TeacherFrame.getT1().getText().trim().matches("^[1-9][0-9]*([.][0-9]{1,2})?$")) {
						int classId = Integer.valueOf(TeacherFrame.getT1().getText().trim());
						List<Student> list = courseService.getClassNoGrade(classId);
						List<Student> result = courseService.searchByGrade(studentList, list);
						TeacherFrame.p1.removeAll();
						TeacherFrame.p1.repaint();
						TeacherFrame.p1.add(StudentJPanel.getStudentTablePanel(result));
						TeacherFrame.p1.revalidate();
					} else {
						JOptionPane.showMessageDialog(studentJPanel, "请输入数字", "输入错误", JOptionPane.ERROR_MESSAGE);
					}
				} else if (TeacherFrame.comboBox1.getSelectedIndex() == 1) {

					if (TeacherFrame.getT1().getText().trim().matches("^[\\u4E00-\\u9FA5]{2,4}$")) {
						String stuNo = TeacherFrame.getT1().getText().trim();
						List<Student> list = courseService.getStuNoGrade(stuNo);
						List<Student> result = courseService.searchByGrade(studentList, list);
						TeacherFrame.p1.add(StudentJPanel.getStudentTablePanel(result), BorderLayout.CENTER);
						TeacherFrame.p1.revalidate();
					} else {
						JOptionPane.showMessageDialog(studentJPanel, "请输入汉字", "输入错误", JOptionPane.ERROR_MESSAGE);
					}
				} else if (TeacherFrame.getT1().getText().trim().matches("^[\\u4E00-\\u9FA5]{2,4}$")) {
					String couName = TeacherFrame.getT1().getText().trim();
					List<Student> list = courseService.getCourseNoGrade(couName);
					List<Student> result = courseService.searchByGrade(studentList, list);
					TeacherFrame.p1.add(StudentJPanel.getStudentTablePanel(result), BorderLayout.CENTER);
					TeacherFrame.p1.revalidate();
				} else {
					JOptionPane.showMessageDialog(teacherFrame, "请输入汉字", "输入错误", JOptionPane.ERROR_MESSAGE);
				}
			} else {
				JOptionPane.showMessageDialog(teacherFrame, "不能为空", "输入错误", JOptionPane.ERROR_MESSAGE);
			}

		// 打开新增课程对话框
		} else if ("addCourseDialog".equals(e.getActionCommand())) {
			courseDialog = new CourseDialog(courseJPanel, "添加课程", null);
		}
		// 新增课程提交
		else if ("addPost".equals(e.getActionCommand())) {
			Course newCourse = null;
			newCourse = this.getCourseInstance();
			if (newCourse != null) {
				courseService.addCourse(newCourse);
				JOptionPane.showMessageDialog(courseJPanel, "添加" + newCourse.getCouId() + "号课程成功！");
				courseDialog.dispose();
				CourseJPanel.refresh(courseService.findAllCourse());
			} else {
				JOptionPane.showMessageDialog(courseJPanel, "添加课程失败！");
			}
		}
		// 打开课程查询对话框
		else if ("searchCourseDialog".equals(e.getActionCommand())) {
			List<Course> courseList = new ArrayList<Course>();
			for (Course course : courseService.findAllCourse()) {
				courseList.add(course);
			}

			if (courseJPanel.getSearchTextField().getText().trim() != null
					&& !"".equals(courseJPanel.getSearchTextField().getText().trim())) {
				if (CourseJPanel.comboBox.getSelectedIndex() == 0) {
					if (courseJPanel.getSearchTextField().getText().trim().matches("^[1-9][0-9]*([.][0-9]{1,2})?$")) {
						int couId = Integer.valueOf(courseJPanel.getSearchTextField().getText().trim());
						Course course = new Course();
						course.setCouId(couId);

						List<Course> result = courseService.searchByCourseId(courseList, course);
						courseJPanel.showSearchResult(result);
					} else {
						JOptionPane.showMessageDialog(courseJPanel, "请输入数字", "输入错误", JOptionPane.ERROR_MESSAGE);
					}
				} else if (courseJPanel.getSearchTextField().getText().trim().matches("^[\\u4E00-\\u9FA5]{2,4}$")) {
					String courseName = courseJPanel.getSearchTextField().getText().trim();
					Course course = courseService.getCourseOne(courseName);
					List<Course> result = courseService.searchByCourseId(courseList, course);
					courseJPanel.showSearchResult(result);

				} else {
					JOptionPane.showMessageDialog(courseJPanel, "请输入汉字", "输入错误", JOptionPane.ERROR_MESSAGE);

				}
			}
			// 打开课程修改对话框
		} else if ("updateCourseDialog".equals(e.getActionCommand())) {
			int isbn = courseJPanel.getIsbn();
			if (isbn < 0) {
				JOptionPane.showMessageDialog(courseJPanel, "请选择一行数据！");
			} else {
				Course course = courseService.findAllCourse().get(courseJPanel.getIsbn());
				courseDialog = new CourseDialog(courseJPanel, "修改课程", course);
			}
		}
		// 修改课程提交
		else if ("updatePost".equals(e.getActionCommand())) {
			Course updatedCourse = this.getCourseInstance();
			if (updatedCourse != null) {
				courseService.updateCourse(updatedCourse);
				JOptionPane.showMessageDialog(courseJPanel, updatedCourse.getCouId() + "号课程修改成功！");
				courseDialog.dispose();
				CourseJPanel.refresh(courseService.findAllCourse());
			} else {
				JOptionPane.showMessageDialog(courseJPanel, "更新课程失败！");
			}
		}
		// 删除课程操作
		else if ("deleteCourseDialog".equals(e.getActionCommand())) {
			int isbn = courseJPanel.getIsbn();
			if (isbn < 0) {
				JOptionPane.showMessageDialog(courseJPanel, "请选择一行数据！");
			} else {
				Course course = courseService.findAllCourse().get(courseJPanel.getIsbn());
				courseService.deleteCourse(course.getCouId());
				JOptionPane.showMessageDialog(courseJPanel, "删除" + course.getCouId() + "号课程成功！");
				CourseJPanel.refresh(courseService.findAllCourse());
			}

		}
		// 刷新课程列表
		else if ("refreshCourseFrame".equals(e.getActionCommand())) {
			CourseJPanel.refresh(courseService.findAllCourse());

		}

		// 打开新增教务员对话框
		else if ("addDeanDialog".equals(e.getActionCommand())) {

			deanDialog = new DeanDialog(deanJPanel, "添加教务员", null);
		}
		// 新增教务员提交
		else if ("addDeanPost".equals(e.getActionCommand())) {
			Dean newDean = null;
			newDean = this.getDeanInstance();
			if (newDean != null) {
				courseService.addDean(newDean);
				JOptionPane.showMessageDialog(deanJPanel, "添加" + newDean.getDeaId() + "号教务员成功！");
				deanDialog.dispose();
				DeanJPanel.refreshDean(courseService.findAllDean());
			} else {
				JOptionPane.showMessageDialog(deanJPanel, "添加教务员失败！");
			}
		}

		// 打开教务员查询对话框
		else if ("searchDeanDialog".equals(e.getActionCommand())) {
			List<Dean> deanList = new ArrayList<Dean>();
			for (Dean dean : courseService.findAllDean()) {
				deanList.add(dean);
			}
			if (deanJPanel.getSearchTextField().getText().trim() != null
					&& !"".equals(deanJPanel.getSearchTextField().getText().trim())) {
				if (DeanJPanel.comboBox.getSelectedIndex() == 0) {
					if (deanJPanel.getSearchTextField().getText().trim().matches("^[1-9][0-9]*([.][0-9]{1,2})?$")) {
						int deaId = Integer.valueOf(deanJPanel.getSearchTextField().getText().trim());
						Dean dean = new Dean();
						dean.setDeaId(deaId);
						List<Dean> result = courseService.searchByDeanId(deanList, dean);
						deanJPanel.showDeanSearchResult(result);

					} else {
						JOptionPane.showMessageDialog(deanJPanel, "请输入数字", "输入错误", JOptionPane.ERROR_MESSAGE);
					}
				} else if (deanJPanel.getSearchTextField().getText().trim().matches("^[\\u4E00-\\u9FA5]{2,4}$")) {
					String deaName = deanJPanel.getSearchTextField().getText().trim();
					Dean dean = courseService.getDeanOne(deaName);
					List<Dean> result = courseService.searchByDeanId(deanList, dean);
					deanJPanel.showDeanSearchResult(result);

				} else {
					JOptionPane.showMessageDialog(deanJPanel, "请输入汉字", "输入错误", JOptionPane.ERROR_MESSAGE);
				}
			}
			// 打开教务员修改对话框
		} else if ("updateDeanDialog".equals(e.getActionCommand())) {
			int isbn = deanJPanel.getDeanIsbn();
			if (isbn < 0) {
				JOptionPane.showMessageDialog(deanJPanel, "请选择一行数据！");
			} else {
				Dean dean = courseService.findAllDean().get(deanJPanel.getDeanIsbn());
				deanDialog = new DeanDialog(deanJPanel, "修改教务员", dean);
			}
		}
		// 修改教务员提交
		else if ("updateDeanPost".equals(e.getActionCommand())) {
			Dean updatedDean = this.getDeanInstance();
			if (updatedDean != null) {
				courseService.updateDean(updatedDean);
				JOptionPane.showMessageDialog(deanJPanel, updatedDean.getDeaId() + "号教务员修改成功！");
				deanDialog.dispose();
				DeanJPanel.refreshDean(courseService.findAllDean());
			} else {
				JOptionPane.showMessageDialog(deanJPanel, "更新教务员失败！");
			}
		}
		// 删除教务员操作
		else if ("deleteDeanDialog".equals(e.getActionCommand())) {
			int isbn = deanJPanel.getDeanIsbn();
			if (isbn < 0) {
				JOptionPane.showMessageDialog(deanJPanel, "请选择一行数据！");
			} else {
				Dean dean = courseService.findAllDean().get(deanJPanel.getDeanIsbn());
				courseService.deleteDean(dean.getDeaId());
				JOptionPane.showMessageDialog(deanJPanel, "删除" + dean.getDeaId() + "号教务员成功！");
				DeanJPanel.refreshDean(courseService.findAllDean());
			}

		}
		// 刷新教务员列表
		else if ("refreshDeanFrame".equals(e.getActionCommand())) {
			DeanJPanel.refreshDean(courseService.findAllDean());
		}

		// 打开新增教师对话框
		else if ("addTeacherDialog".equals(e.getActionCommand())) {

			teacherDialog = new TeacherDialog(teacherJPanel, "添加教师", null);
		}
		// 新增教师提交
		else if ("addTeacherPost".equals(e.getActionCommand())) {
			Teacher newTeacher = null;
			newTeacher = this.getTeacherInstance();
			if (newTeacher != null) {
				courseService.addTeacher(newTeacher);
				JOptionPane.showMessageDialog(teacherJPanel, "添加" + newTeacher.getTeaId() + "号教师成功！");
				teacherDialog.dispose();
				TeacherJPanel.refreshTeacher(courseService.findAllTeacher());
			} else {
				JOptionPane.showMessageDialog(teacherJPanel, "添加教师失败！");
			}
		}
		// 打开教师查询对话框
		else if ("searchTeacherDialog".equals(e.getActionCommand())) {
			List<Teacher> teacherList = new ArrayList<Teacher>();
			for (Teacher teacher : courseService.findAllTeacher()) {
				teacherList.add(teacher);
			}
			if (teacherJPanel.getSearchTextField().getText().trim() != null
					&& !"".equals(teacherJPanel.getSearchTextField().getText().trim())) {
				if (TeacherJPanel.comboBox.getSelectedIndex() == 0) {
					if (teacherJPanel.getSearchTextField().getText().trim().matches("^[1-9][0-9]*([.][0-9]{1,2})?$")) {
						int teaId = Integer.valueOf(teacherJPanel.getSearchTextField().getText().trim());
						Teacher teacher = new Teacher();
						teacher.setTeaId(teaId);
						List<Teacher> result = courseService.searchByTeacherId(teacherList, teacher);
						teacherJPanel.showTeacherSearchResult(result);
					} else {
						JOptionPane.showMessageDialog(teacherJPanel, "请输入数字", "输入错误", JOptionPane.ERROR_MESSAGE);
					}
				} else if (teacherJPanel.getSearchTextField().getText().trim().matches("^[\\u4E00-\\u9FA5]{2,4}$")) {
					String teacherName = teacherJPanel.getSearchTextField().getText().trim();
					Teacher teacher = courseService.getTeacherOne(teacherName);
					List<Teacher> result = courseService.searchByTeacherId(teacherList, teacher);
					teacherJPanel.showTeacherSearchResult(result);

				} else {
					JOptionPane.showMessageDialog(teacherJPanel, "请输入汉字", "输入错误", JOptionPane.ERROR_MESSAGE);
				}

			}

			// 打开教师修改对话框
		} else if ("updateTeacherDialog".equals(e.getActionCommand())) {
			int isbn = teacherJPanel.getTeacherIsbn();
			if (isbn < 0) {
				JOptionPane.showMessageDialog(teacherJPanel, "请选择一行数据！");
			} else {
				Teacher teacher = courseService.findAllTeacher().get(teacherJPanel.getTeacherIsbn());
				teacherDialog = new TeacherDialog(teacherJPanel, "修改教师", teacher);
			}
		}
		// 修改教师提交
		else if ("updateTeacherPost".equals(e.getActionCommand())) {
			Teacher updatedTeacher = this.getTeacherInstance();
			if (updatedTeacher != null) {
				courseService.updateTeacher(updatedTeacher);
				JOptionPane.showMessageDialog(teacherJPanel, updatedTeacher.getTeaId() + "号教师修改成功！");
				teacherDialog.dispose();
				TeacherJPanel.refreshTeacher(courseService.findAllTeacher());
			} else {
				JOptionPane.showMessageDialog(teacherJPanel, "更新教师失败！");
			}
		}
		// 删除教师操作
		else if ("deleteTeacherDialog".equals(e.getActionCommand())) {
			int isbn = teacherJPanel.getTeacherIsbn();
			System.out.println(isbn);
			if (isbn < 0) {
				JOptionPane.showMessageDialog(teacherJPanel, "请选择一行数据！");
			} else {
				Teacher teacher = courseService.findAllTeacher().get(teacherJPanel.getTeacherIsbn());
				courseService.deleteTeacher(teacher.getTeaId());
				JOptionPane.showMessageDialog(teacherJPanel, "删除" + teacher.getTeaId() + "号教师成功！");
				TeacherJPanel.refreshTeacher(courseService.findAllTeacher());
			}

		}
		// 刷新教师列表
		else if ("refreshTeacherFrame".equals(e.getActionCommand())) {
			TeacherJPanel.refreshTeacher(courseService.findAllTeacher());
		}

		// 打开新增学生对话框
		else if ("addStudentDialog".equals(e.getActionCommand())) {
			studentDialog = new StudentDialog(studentJPanel, "添加学生", null);
		}
		// 新增学生提交
		else if ("addStudentPost".equals(e.getActionCommand())) {
			Student newStudent = null;
			newStudent = this.getStudentInstance();
			if (newStudent != null) {
				courseService.addStudent(newStudent);
				JOptionPane.showMessageDialog(studentJPanel, "添加" + newStudent.getStuId() + "号学生成功！");
				studentDialog.dispose();
				StudentJPanel.refreshStudent(courseService.findAllStudent());
			} else {
				JOptionPane.showMessageDialog(studentJPanel, "添加学生失败！");
			}
		}
		// 打开学生查询对话框
		else if ("searchStudentDialog".equals(e.getActionCommand())) {
			List<Student> studentList = new ArrayList<Student>();
			for (Student student : courseService.findAllStudent()) {
				studentList.add(student);
			}
			if (studentJPanel.getSearchTextField().getText().trim() != null
					&& !"".equals(studentJPanel.getSearchTextField().getText().trim())) {
				if (StudentJPanel.comboBox.getSelectedIndex() == 0) {
					if (studentJPanel.getSearchTextField().getText().trim().matches("^[1-9][0-9]*([.][0-9]{1,2})?$")) {
						int studentId = Integer.valueOf(studentJPanel.getSearchTextField().getText().trim());
						Student student = new Student();
						student.setStuId(studentId);
						List<Student> result = courseService.searchByStudentId(studentList, student);
						studentJPanel.showStudentSearchResult(result);
					} else {
						JOptionPane.showMessageDialog(studentJPanel, "请输入数字", "输入错误", JOptionPane.ERROR_MESSAGE);
					}
				} else if (studentJPanel.getSearchTextField().getText().trim().matches("^[\\u4E00-\\u9FA5]{2,4}$")) {
					String studentName = studentJPanel.getSearchTextField().getText().trim();
					Student student = courseService.getStudentOne(studentName);
					List<Student> result = courseService.searchByStudentId(studentList, student);
					studentJPanel.showStudentSearchResult(result);

				} else {
					JOptionPane.showMessageDialog(studentJPanel, "请输入汉字", "输入错误", JOptionPane.ERROR_MESSAGE);
				}

			}
			// 打开修改学生对话框
		} else if ("updateStudentDialog".equals(e.getActionCommand())) {
			int isbn = studentJPanel.getStudentIsbn();
			if (isbn < 0) {
				JOptionPane.showMessageDialog(studentJPanel, "请选择一行数据！");
			} else {
				Student student = courseService.findAllStudent().get(studentJPanel.getStudentIsbn());
				studentDialog = new StudentDialog(studentJPanel, "修改学生", student);
			}
		}
		// 修改学生提交
		else if ("updateStudentPost".equals(e.getActionCommand())) {
			Student updatedStudent = this.getStudentInstance();
			if (updatedStudent != null) {
				courseService.updateStudent(updatedStudent);
				JOptionPane.showMessageDialog(studentJPanel, updatedStudent.getStuId() + "号学生修改成功！");
				studentDialog.dispose();
				StudentJPanel.refreshStudent(courseService.findAllStudent());
			} else {
				JOptionPane.showMessageDialog(studentJPanel, "更新学生失败！");
			}
		}
		// 删除学生操作
		else if ("deleteStudentDialog".equals(e.getActionCommand())) {
			int isbn = studentJPanel.getStudentIsbn();
			if (isbn < 0) {
				JOptionPane.showMessageDialog(studentJPanel, "请选择一行数据！");
			} else {
				Student student = courseService.findAllStudent().get(studentJPanel.getStudentIsbn());
				courseService.deleteStudent(student.getStuId());
				JOptionPane.showMessageDialog(studentJPanel, "删除" + student.getStuId() + "号学生成功！");
				StudentJPanel.refreshStudent(courseService.findAllStudent());
			}
		}
		// 刷新学生列表窗口
		else if ("refreshStudentFrame".equals(e.getActionCommand())) {
			StudentJPanel.refreshStudent(courseService.findAllStudent());

		}
	}
	
//得到学生基本信息
	private Student getStudentInstance() {
		int stuId = 0;
		String stuNo = null;
		String stuName = null;
		String stuSex = null;
		Date stuAge = null;
		String stuMajor = null;
		int stuClassNo = 0;
		int couId = 0;
		String couName = null;
		int stuGrade = 0;
		java.sql.Date sqlDate = null;
		Course course = null;

		Student student = null;
		String stuIdInput = studentDialog.getStudentIdTextField().getText().trim();
		if (stuIdInput != null && !"".equals(stuIdInput)) {
			if (stuIdInput.matches("^[1-9][0-9]*([.][0-9]{1,2})?$")) {
				stuId = Integer.parseInt(stuIdInput);
			} else {
				JOptionPane.showMessageDialog(studentFrame, "编号必须是正整数类型", "输入错误", JOptionPane.ERROR_MESSAGE);
			}
		} else {
			JOptionPane.showMessageDialog(studentFrame, "编号不能为空", "输入错误", JOptionPane.ERROR_MESSAGE);
		}

		String stuNoInput = studentDialog.getStudentNoTextField().getText().trim();
		if (stuNoInput != null && !"".equals(stuNoInput)) {
			stuNo = stuNoInput;
		} else {
			JOptionPane.showMessageDialog(studentFrame, "学号不能为空", "输入错误", JOptionPane.ERROR_MESSAGE);
		}
		String stuNameInput = studentDialog.getStudentNameTextField().getText().trim();
		if (stuNameInput != null && !"".equals(stuNameInput)) {
			stuName = stuNameInput;
		} else {
			JOptionPane.showMessageDialog(studentFrame, "姓名不能为空", "输入错误", JOptionPane.ERROR_MESSAGE);
		}
		String stuSexInput = studentDialog.getStudentSexTextField().getText().trim();
		if (stuSexInput != null && !"".equals(stuSexInput)) {
			stuSex = stuSexInput;
		} else {
			JOptionPane.showMessageDialog(studentFrame, "性别不能为空", "输入错误", JOptionPane.ERROR_MESSAGE);
		}
		String dateInput = studentDialog.getStudentAgeTextField().getText().trim();
		if (dateInput != null && !"".equals(dateInput)) {
			SimpleDateFormat ft = new SimpleDateFormat("yyyy-MM-dd");
			try {
				stuAge = new SimpleDateFormat("yyyy-MM-dd").parse(dateInput);
				sqlDate = new java.sql.Date(stuAge.getTime());
			} catch (ParseException e) {
				JOptionPane.showMessageDialog(studentFrame, "年龄类型错误", "输入错误", JOptionPane.ERROR_MESSAGE);
			}
		} else {
			JOptionPane.showMessageDialog(studentFrame, "年龄不能为空", "输入错误", JOptionPane.ERROR_MESSAGE);
		}
		String stuMajorInput = studentDialog.getStudentMajorTextField().getText().trim();
		if (stuMajorInput != null && !"".equals(stuMajorInput)) {
			stuMajor = stuMajorInput;
		} else {
			JOptionPane.showMessageDialog(studentFrame, "专业不能为空", "输入错误", JOptionPane.ERROR_MESSAGE);
		}
		String stuClassNoInput = studentDialog.getStudentClassNoTextField().getText().trim();
		if (stuClassNoInput != null && !"".equals(stuIdInput)) {
			if (stuClassNoInput.matches("^[1-9][0-9]*([.][0-9]{1,2})?$")) {
				stuClassNo = Integer.parseInt(stuClassNoInput);
			} else {
				JOptionPane.showMessageDialog(studentFrame, "班级号必须是正整数类型", "输入错误", JOptionPane.ERROR_MESSAGE);
			}
		} else {
			JOptionPane.showMessageDialog(studentFrame, "班级号不能为空", "输入错误", JOptionPane.ERROR_MESSAGE);
		}
		String couIdInput = studentDialog.getCourseIdTextField().getText().trim();
		if (couIdInput != null && !"".equals(couIdInput)) {
			if (couIdInput.matches("^[1-9][0-9]*([.][0-9]{1,2})?$")) {
				couId = Integer.parseInt(couIdInput);
				course = courseService.getCourse(couId);
			} else {
				JOptionPane.showMessageDialog(studentFrame, "课程编号必须是正整数类型", "输入错误", JOptionPane.ERROR_MESSAGE);
			}
		} else {
			JOptionPane.showMessageDialog(studentFrame, "课程编号不能为空", "输入错误", JOptionPane.ERROR_MESSAGE);
		}
		String stuGradeInput = studentDialog.getStudentGradeTextField().getText().trim();
		if (stuGradeInput != null && !"".equals(stuGradeInput)) {
			if (stuGradeInput.matches("^[0-9]*$")) {
				stuGrade = Integer.parseInt(stuGradeInput);
			} else {
				JOptionPane.showMessageDialog(studentFrame, "成绩必须是数字类型", "输入错误", JOptionPane.ERROR_MESSAGE);
			}
		} else {
			JOptionPane.showMessageDialog(studentFrame, "成绩不能为空", "输入错误", JOptionPane.ERROR_MESSAGE);
		}

		if (stuId > 0 && stuNo != null && stuName != null && stuSex != null && sqlDate != null && stuMajor != null
				&& stuClassNo > 0 && couId > 0 && stuGrade > 0 && course != null) {
			student = new Student(stuId, stuNo, stuName, stuSex, sqlDate, stuMajor, stuClassNo, stuGrade, course);
		}
		return student;
	}

	//得到教师基本信息
	private Teacher getTeacherInstance() {
		int teaId = 0;
		String teaNo = null;
		String teaName = null;
		String teaSex = null;
		Date teaAge = null;
		int couId = 0;
		java.sql.Date sqlDate = null;
		Course course = null;
		Teacher teacher = null;
		String teaIdInput = teacherDialog.getTeacherIdTextField().getText().trim();
		if (teaIdInput != null && !"".equals(teaIdInput)) {
			if (teaIdInput.matches("^[1-9][0-9]*([.][0-9]{1,2})?$")) {
				teaId = Integer.parseInt(teaIdInput);
			} else {
				JOptionPane.showMessageDialog(teacherFrame, "编号必须是正整数类型", "输入错误", JOptionPane.ERROR_MESSAGE);
			}
		} else {
			JOptionPane.showMessageDialog(teacherFrame, "编号不能为空", "输入错误", JOptionPane.ERROR_MESSAGE);
		}

		String teaNoInput = teacherDialog.getTeacherNoTextField().getText().trim();
		if (teaNoInput != null && !"".equals(teaNoInput)) {
			teaNo = teaNoInput;
		} else {
			JOptionPane.showMessageDialog(teacherFrame, "教职工号不能为空", "输入错误", JOptionPane.ERROR_MESSAGE);
		}
		String teaNameInput = teacherDialog.getTeacherNameTextField().getText().trim();
		if (teaNameInput != null && !"".equals(teaNameInput)) {
			teaName = teaNameInput;
		} else {
			JOptionPane.showMessageDialog(teacherFrame, "姓名不能为空", "输入错误", JOptionPane.ERROR_MESSAGE);
		}
		String teaSexInput = teacherDialog.getTeacherSexTextField().getText().trim();
		if (teaSexInput != null && !"".equals(teaSexInput)) {
			teaSex = teaSexInput;
		} else {
			JOptionPane.showMessageDialog(teacherFrame, "性别不能为空", "输入错误", JOptionPane.ERROR_MESSAGE);
		}
		String dateInput = teacherDialog.getTeacherAgeTextField().getText().trim();
		if (dateInput != null && !"".equals(dateInput)) {
			SimpleDateFormat ft = new SimpleDateFormat("yyyy-MM-dd");
			try {
				teaAge = new SimpleDateFormat("yyyy-MM-dd").parse(dateInput);
				sqlDate = new java.sql.Date(teaAge.getTime());
			} catch (ParseException e) {
				JOptionPane.showMessageDialog(teacherFrame, "年龄类型错误", "输入错误", JOptionPane.ERROR_MESSAGE);
			}
		} else {
			JOptionPane.showMessageDialog(teacherFrame, "年龄不能为空", "输入错误", JOptionPane.ERROR_MESSAGE);
		}
		String couIdInput = teacherDialog.getCourseIdTextField().getText().trim();
		if (couIdInput != null && !"".equals(couIdInput)) {
			if (couIdInput.matches("^[1-9][0-9]*([.][0-9]{1,2})?$")) {
				couId = Integer.parseInt(couIdInput);
				course = courseService.getCourse(couId);
			} else {
				JOptionPane.showMessageDialog(teacherFrame, "课程编号必须是正整数类型", "输入错误", JOptionPane.ERROR_MESSAGE);
			}
		} else {
			JOptionPane.showMessageDialog(teacherFrame, "课程编号不能为空", "输入错误", JOptionPane.ERROR_MESSAGE);
		}
		if (teaId > 0 && teaNo != null && teaName != null && teaSex != null && sqlDate != null && course != null) {
			teacher = new Teacher(teaId, teaNo, teaName, teaSex, sqlDate, course);
		}
		return teacher;
	}

	//得到课程基本信息
	private Course getCourseInstance() {
		int couId = 0;
		String couType = null;
		String couNo = null;
		String couName = null;
		String couDetail = null;
		int couCredit = 0;
		int teaId = 0;
		Teacher teacher = null;
		String teaName = null;
		int maxNumber = 0;
		int selectNumber = 0;
		Course course = null;
		String couIdInput = courseDialog.getCourseIdTextField().getText().trim();
		if (couIdInput != null && !"".equals(couIdInput)) {
			if (couIdInput.matches("^[1-9][0-9]*([.][0-9]{1,2})?$")) {
				couId = Integer.parseInt(couIdInput);
			} else {
				JOptionPane.showMessageDialog(courseFrame, "编号必须是正整数类型", "输入错误", JOptionPane.ERROR_MESSAGE);
			}
		} else {
			JOptionPane.showMessageDialog(courseFrame, "编号不能为空", "输入错误", JOptionPane.ERROR_MESSAGE);
		}
		String couTypeInput = courseDialog.getCourseTypeTextField().getText().trim();
		if (couTypeInput != null && !"".equals(couTypeInput)) {
			couType = couTypeInput;
		} else {
			JOptionPane.showMessageDialog(courseFrame, "课程类型不能为空", "输入错误", JOptionPane.ERROR_MESSAGE);
		}

		String couNoInput = courseDialog.getCourseNoTextField().getText().trim();
		if (couNoInput != null && !"".equals(couNoInput)) {
			couNo = couNoInput;
		} else {
			JOptionPane.showMessageDialog(courseFrame, "课程号不能为空", "输入错误", JOptionPane.ERROR_MESSAGE);
		}
		String couNameInput = courseDialog.getCourseNameTextField().getText().trim();
		if (couNameInput != null && !"".equals(couNameInput)) {
			couName = couNameInput;
		} else {
			JOptionPane.showMessageDialog(courseFrame, "课程名不能为空", "输入错误", JOptionPane.ERROR_MESSAGE);
		}
		String couDetailInput = courseDialog.getCourseDetailTextField().getText().trim();
		if (couDetailInput != null && !"".equals(couDetailInput)) {
			couDetail = couDetailInput;
		} else {
			JOptionPane.showMessageDialog(courseFrame, "时间/地点不能为空", "输入错误", JOptionPane.ERROR_MESSAGE);
		}
		String couCreditInput = courseDialog.getCourseCreditTextField().getText().trim();
		if (couCreditInput != null && !"".equals(couCreditInput)) {
			if (couIdInput.matches("^[1-9][0-9]*([.][0-9]{1,2})?$")) {
				couCredit = Integer.parseInt(couCreditInput);
			} else {
				JOptionPane.showMessageDialog(courseFrame, "学分必须是正整数类型", "输入错误", JOptionPane.ERROR_MESSAGE);
			}
		} else {
			JOptionPane.showMessageDialog(courseFrame, "学分不能为空", "输入错误", JOptionPane.ERROR_MESSAGE);
		}
		String teaIdInput = courseDialog.getTeacherIdTextField().getText().trim();
		if (teaIdInput != null && !"".equals(teaIdInput)) {
			if (teaIdInput.matches("^[1-9][0-9]*([.][0-9]{1,2})?$")) {
				teaId = Integer.parseInt(teaIdInput);
				teacher = courseService.getTeacher(teaId);
			} else {
				JOptionPane.showMessageDialog(courseFrame, "教师编号必须是正整数类型", "输入错误", JOptionPane.ERROR_MESSAGE);
			}
		} else {
			JOptionPane.showMessageDialog(courseFrame, "教师编号不能为空", "输入错误", JOptionPane.ERROR_MESSAGE);
		}
		String maxNumberInput = courseDialog.getMaxNumberTextField().getText().trim();
		if (maxNumberInput != null && !"".equals(maxNumberInput)) {
			if (maxNumberInput.matches("^[1-9][0-9]*([.][0-9]{1,2})?$")) {
				maxNumber = Integer.parseInt(maxNumberInput);
			} else {
				JOptionPane.showMessageDialog(courseFrame, "课程容量必须是正整数类型", "输入错误", JOptionPane.ERROR_MESSAGE);
			}
		} else {
			JOptionPane.showMessageDialog(courseFrame, "课程容量不能为空", "输入错误", JOptionPane.ERROR_MESSAGE);
		}
		String selectNumberInput = courseDialog.getSelectNumberTextField().getText().trim();
		if (selectNumberInput != null && !"".equals(selectNumberInput)) {
			if (selectNumberInput.matches("^[0-9]*$")) {
				selectNumber = Integer.parseInt(selectNumberInput);
			} else {
				JOptionPane.showMessageDialog(courseFrame, "已选人数必须是数字类型", "输入错误", JOptionPane.ERROR_MESSAGE);
			}
		} else {
			JOptionPane.showMessageDialog(courseFrame, "已选人数不能为空", "输入错误", JOptionPane.ERROR_MESSAGE);
		}
		if (couId > 0 && couType != null && couNo != null && couName != null && couDetail != null && couCredit > 0
				&& teacher != null && maxNumber > 0 && selectNumber >= 0) {
			course = new Course(couId, couType, couNo, couName, couDetail, couCredit, maxNumber, selectNumber, teacher);
		}
		return course;
	}
	
	//得到教务员基本信息
	private Dean getDeanInstance() {
		int deaId = 0;
		String deaNo = null;
		String deaName = null;
		String deaSex = null;
		Date deaAge = null;
		java.sql.Date sqlDate = null;
		Dean dean = null;
		String deaIdInput = deanDialog.getDeanIdTextField().getText().trim();
		if (deaIdInput != null && !"".equals(deaIdInput)) {
			if (deaIdInput.matches("^[1-9][0-9]*([.][0-9]{1,2})?$")) {
				deaId = Integer.parseInt(deaIdInput);
			} else {
				JOptionPane.showMessageDialog(deanFrame, "编号必须是数字类型", "输入错误", JOptionPane.ERROR_MESSAGE);
			}
		} else {
			JOptionPane.showMessageDialog(deanFrame, "编号不能为空", "输入错误", JOptionPane.ERROR_MESSAGE);
		}

		String deaNoInput = deanDialog.getDeanNoTextField().getText().trim();
		if (deaNoInput != null && !"".equals(deaNoInput)) {
			deaNo = deaNoInput;
		} else {
			JOptionPane.showMessageDialog(deanFrame, "教职工号不能为空", "输入错误", JOptionPane.ERROR_MESSAGE);
		}
		String deaNameInput = deanDialog.getDeanNameTextField().getText().trim();
		if (deaNameInput != null && !"".equals(deaNameInput)) {
			deaName = deaNameInput;
		} else {
			JOptionPane.showMessageDialog(deanFrame, "姓名不能为空", "输入错误", JOptionPane.ERROR_MESSAGE);
		}
		String deaSexInput = deanDialog.getDeanSexTextField().getText().trim();
		if (deaSexInput != null && !"".equals(deaSexInput)) {
			deaSex = deaSexInput;
		} else {
			JOptionPane.showMessageDialog(deanFrame, "性别不能为空", "输入错误", JOptionPane.ERROR_MESSAGE);
		}
		String dateInput = deanDialog.getDeanAgeTextField().getText().trim();
		if (dateInput != null && !"".equals(dateInput)) {
			SimpleDateFormat ft = new SimpleDateFormat("yyyy-MM-dd");
			try {
				deaAge = new SimpleDateFormat("yyyy-MM-dd").parse(dateInput);
				sqlDate = new java.sql.Date(deaAge.getTime());
			} catch (ParseException e) {
				JOptionPane.showMessageDialog(deanFrame, "年龄类型错误", "输入错误", JOptionPane.ERROR_MESSAGE);
			}
		} else {
			JOptionPane.showMessageDialog(deanFrame, "年龄不能为空", "输入错误", JOptionPane.ERROR_MESSAGE);
		}

		if (deaId > 0 && deaNo != null && deaName != null && deaSex != null && sqlDate != null) {
			dean = new Dean(deaId, deaNo, deaName, deaSex, sqlDate);
		}
		return dean;
	}

	public void setStudentFrame(StudentFrame studentFrame) {
		this.studentFrame = studentFrame;

	}

	public void setLoginFrame(LoginFrame loginFrame) {
		this.loginFrame = loginFrame;

	}

	public void setDeanFrame(DeanFrame deanFrame) {
		this.deanFrame = deanFrame;

	}

	public void setTeacherFrame(TeacherFrame teacherFrame) {
		this.teacherFrame = teacherFrame;

	}

	public void setCourseAddDialog(CourseDialog courseDialog) {
		this.courseDialog = courseDialog;

	}

	public void setCourseFrame(CourseFrame courseFrame) {
		this.courseFrame = courseFrame;

	}

	public CourseServiceImpl getCourseService() {
		return courseService;
	}

	public void setDeanAddDialog(DeanDialog deanDialog) {
		this.deanDialog = deanDialog;

	}

	public void setTeacherAddDialog(TeacherDialog teacherDialog) {
		this.teacherDialog = teacherDialog;

	}

	public void setStudentAddDialog(StudentDialog studentDialog) {
		this.studentDialog = studentDialog;

	}

	public void setDeanPanel(DeanJPanel deanJPanel) {
		this.deanJPanel = deanJPanel;
	}

	public void setStudentPanel(StudentJPanel studentJPanel) {
		this.studentJPanel = studentJPanel;
	}

	public void setTeachertPanel(TeacherJPanel teacherJPanel) {
		this.teacherJPanel = teacherJPanel;

	}

	public void setCoursePanel(CourseJPanel courseJPanel) {
		this.courseJPanel = courseJPanel;

	}

}
>>>>>>> refs/remotes/origin/master
